package com.ec.generator.modules.gen.controller;

import com.ec.core.common.core.api.Result;
import com.ec.core.common.core.api.ResponseMsg;
import com.ec.generator.modules.gen.dto.GenFuncDTO;
import com.ec.generator.modules.gen.dto.SyncFieldDTO;
import com.ec.generator.modules.gen.service.IGenCodeService;
import com.ec.core.mybatis.groups.ValidatorGroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


/**
 * 生成代码接口
 * @author Eric Lee
 * @time: 2022/1/17 20:08
 */
@RestController
@RequestMapping("/gen")
@Slf4j
public class GenCodeController {
    @Resource
    private IGenCodeService genCodeService;

    /**
     * 生成工程脚手架
     */
    @PostMapping("/genScaffold")
    public void genScaffold(@RequestBody Long projectId, HttpServletResponse response) {
        genCodeService.genScaffold(projectId, response);
    }

    /**
     * 生成单表功能
     */
    @PostMapping("/genFun")
    public void genFun(@Validated(ValidatorGroup.Other.class) @RequestBody GenFuncDTO genFuncDTO, HttpServletResponse response) {
        genCodeService.genFun(genFuncDTO, response);
    }

    @PostMapping("/syncField")
    public Result<Void> syncField(@Validated(ValidatorGroup.Other.class) @RequestBody SyncFieldDTO syncFieldDTO) {
        return ResponseMsg.status(genCodeService.syncField(syncFieldDTO));
    }

}
